Skip to content

feat(ast_tools): support #[estree(prepend_to)]#10849

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-07-feat_ast_tools_support_estree_prepend_to_
May 7, 2025
Merged

feat(ast_tools): support #[estree(prepend_to)]#10849
graphite-app[bot] merged 1 commit intomainfrom
05-07-feat_ast_tools_support_estree_prepend_to_

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented May 7, 2025

Add an #[estree(prepend_to = ...)] attribute to accompany #[estree(append_to = ...)].

  • #[estree(prepend_to = target)] prepends the field to start of the target field.
  • #[estree(append_to = target)] appends the field to end of the target field.

This also allow both prepending and appending to the same field. e.g. combining TSThisParameter, FormalParameters, and BindingRestElement into a single array.

@github-actions github-actions bot added A-ast Area - AST A-ast-tools Area - AST tools C-enhancement Category - New feature or request labels May 7, 2025
Copy link
Member Author

overlookmotel commented May 7, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented May 7, 2025

CodSpeed Instrumentation Performance Report

Merging #10849 will create unknown performance changes

Comparing 05-07-feat_ast_tools_support_estree_prepend_to_ (d066516) with main (b16331e)

Summary

🆕 36 new benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 codegen[checker.ts] N/A 22.2 ms N/A
🆕 codegen_sourcemap[checker.ts] N/A 65.2 ms N/A
🆕 formatter[antd.js] N/A 714.3 ms N/A
🆕 formatter[react.development.js] N/A 8.1 ms N/A
🆕 formatter[typescript.js] N/A 1.1 s N/A
🆕 isolated-declarations[vue-id.ts] N/A 58.4 ms N/A
🆕 lexer[RadixUIAdoptionSection.jsx] N/A 21.6 µs N/A
🆕 lexer[antd.js] N/A 24.1 ms N/A
🆕 lexer[cal.com.tsx] N/A 5.8 ms N/A
🆕 lexer[checker.ts] N/A 14.4 ms N/A
🆕 lexer[pdf.mjs] N/A 3.9 ms N/A
🆕 linter[RadixUIAdoptionSection.jsx] N/A 2.7 ms N/A
🆕 linter[cal.com.tsx] N/A 1.2 s N/A
🆕 linter[checker.ts] N/A 3.1 s N/A
🆕 mangler[antd.js] N/A 16 ms N/A
🆕 mangler[react.development.js] N/A 294.1 µs N/A
🆕 mangler[typescript.js] N/A 39.6 ms N/A
🆕 minifier[antd.js] N/A 164.4 ms N/A
🆕 minifier[react.development.js] N/A 1.8 ms N/A
🆕 minifier[typescript.js] N/A 288.7 ms N/A
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@overlookmotel overlookmotel force-pushed the 05-07-feat_ast_tools_support_estree_prepend_to_ branch from 71dfa51 to 83acf70 Compare May 7, 2025 10:05
@overlookmotel overlookmotel marked this pull request as ready for review May 7, 2025 13:01
@overlookmotel overlookmotel requested a review from leaysgur as a code owner May 7, 2025 13:01
@overlookmotel
Copy link
Member Author

Only alters the ESTree generator, no changes to how AST is serialized. So merging without review.

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label May 7, 2025
Copy link
Member Author

overlookmotel commented May 7, 2025

Merge activity

@overlookmotel overlookmotel force-pushed the 05-07-feat_ast_tools_support_estree_prepend_to_ branch from 83acf70 to 7015811 Compare May 7, 2025 13:11
@overlookmotel overlookmotel force-pushed the 05-07-refactor_ast_estree_generalize_concatenating_fields_with_concat2_ branch from 3b4cfea to ff07cc6 Compare May 7, 2025 13:11
Add an `#[estree(prepend_to = ...)]` attribute to accompany `#[estree(append_to = ...)]`.

* `#[estree(prepend_to = target)]` prepends the field to *start* of the target field.
* `#[estree(append_to = target)]` appends the field to *end* of the target field.

This also allow both prepending *and* appending to the same field. e.g. combining `TSThisParameter`, `FormalParameter`s, and `BindingRestElement` into a single array.
@graphite-app graphite-app bot force-pushed the 05-07-refactor_ast_estree_generalize_concatenating_fields_with_concat2_ branch from ff07cc6 to b16331e Compare May 7, 2025 13:25
@graphite-app graphite-app bot force-pushed the 05-07-feat_ast_tools_support_estree_prepend_to_ branch from 7015811 to d066516 Compare May 7, 2025 13:25
graphite-app bot pushed a commit that referenced this pull request May 7, 2025
Pure refactor. Use `#[estree(prepend_to = ...)]` (introduced in #10849) to concatenate directives and statements in ESTree AST.

Previously we had hacks like this:

```rs
pub struct Program<'a> {
    #[estree(rename = "body")]
    pub directives: Vec<'a, Directive<'a>>,
    #[estree(append_to = "directives")]
    pub body: Vec<'a, Statement<'a>>,
}
```

Instead we can do this which is easier to read, and simpler for `oxc_ast_tools` to generate code for:

```rs
pub struct Program<'a> {
    #[estree(prepend_to = "body")]
    pub directives: Vec<'a, Directive<'a>>,
    pub body: Vec<'a, Statement<'a>>,
}
```
Base automatically changed from 05-07-refactor_ast_estree_generalize_concatenating_fields_with_concat2_ to main May 7, 2025 13:31
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 7, 2025
@graphite-app graphite-app bot merged commit d066516 into main May 7, 2025
27 checks passed
@graphite-app graphite-app bot deleted the 05-07-feat_ast_tools_support_estree_prepend_to_ branch May 7, 2025 13:32
graphite-app bot pushed a commit that referenced this pull request May 7, 2025
Pure refactor. Use `#[estree(prepend_to = ...)]` (introduced in #10849) to concatenate directives and statements in ESTree AST.

Previously we had hacks like this:

```rs
pub struct Program<'a> {
    #[estree(rename = "body")]
    pub directives: Vec<'a, Directive<'a>>,
    #[estree(append_to = "directives")]
    pub body: Vec<'a, Statement<'a>>,
}
```

Instead we can do this which is easier to read, and simpler for `oxc_ast_tools` to generate code for:

```rs
pub struct Program<'a> {
    #[estree(prepend_to = "body")]
    pub directives: Vec<'a, Directive<'a>>,
    pub body: Vec<'a, Statement<'a>>,
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-ast-tools Area - AST tools C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant